package com.newtype.meeting.client;

import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.newtype.meeting.client.model.Account;
import com.newtype.meeting.client.model.AccountDetails;
import com.newtype.meeting.client.model.AccountType;
import com.newtype.meeting.client.model.Title;
import com.newtype.meeting.client.service.AccountServiceAsync;
import com.newtype.meeting.client.service.TitleServiceAsync;

public class DevTools {
	private static AccountServiceAsync accountService = Registry
			.get(GMeeting.ACCOUNT_SERVICE);
	private static TitleServiceAsync titleService = Registry
			.get(GMeeting.TITLE_SERVICE);

	public static void addAccount(final String accountID, String password,
			String fullName, String email, String phone,
			final AccountType accountType, String status) {

		Account account = new Account();
		account.setAccountID(accountID);
		account.setPassword(MD5.MD5Encode(password));
		account.setFullName(fullName);
		account.setEmail(email);
		account.setPhone(phone);
		account.setAccountType(accountType);
		account.setStatus(status);

		AccountDetails details = new AccountDetails();
		details.setAddress("蘇州市蘇華路1號世紀金融大廈");
		details.setGender("1");
		account.setDetails(details);

		accountService.addAccount(account, new AsyncCallback<Void>() {
			@Override
			public void onFailure(Throwable caught) {
				caught.printStackTrace();
			}

			@Override
			public void onSuccess(Void result) {
				System.out.println("Account " + accountID + " added as a(n) "
						+ accountType.toString());
			}
		});
	}

	public static void addTitle(final String caption, Integer degree) {
		Title title = new Title(caption, degree);
		titleService.addTitle(title, new AsyncCallback<Void>() {

			@Override
			public void onFailure(Throwable caught) {
				caught.printStackTrace();
			}

			@Override
			public void onSuccess(Void result) {
				System.out.println("Title " + caption + " added.");
			}
		});
	}
}
